home *** CD-ROM | disk | FTP | other *** search
- Path: crc-news.doc.ca!usenet
- From: Slobodan Celenkovic <slobodan@cs.unh.edu>
- Newsgroups: comp.lang.c++,comp.lang.pascal.delphi.misc
- Subject: Re: C++ with Zapp vs. Delphi
- Date: 19 Jan 1996 15:39:51 GMT
- Organization: The Communications Research Centre
- Message-ID: <4doe07$4u8@crc-news.doc.ca>
- References: <4coar6$d4n@sun4.bham.ac.uk> <4coip7$69s@news1.usa.pipeline.com> <DBk8wg2yqjbB083yn@iaccess.za> <4d7pmb$48c8@tigger.cc.uic.edu> <4dk38h$gdr@merlin.delphi.com> <4dksp1$3d6c@tigger.cc.uic.edu> <30fe666e.3349285@130.15.126.54> <4dmjt8$6sv@crc-news.doc.ca> <30ff9519.1799465@130.15.126.54>
- NNTP-Posting-Host: celenkovic.bob.fob003.ic.gc.ca
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.1N (Windows; I; 16bit)
-
-
- dmurdoch@mast.queensu.ca (Duncan Murdoch) wrote:
- >Slobodan Celenkovic <slobodan@cs.unh.edu> wrote:
- >>
- >>No multiple-inheritance, no operator overloading -> Delphi:
- >>===========================================================
- >>
- >>We can't use the abstract item so:
- >>
- >>class IntItem(some other class); <- data classes
- >>class StringItem(some other class);
- >>class MoneyItem(some other class);
- >
- >Why on earth would you bother to declare those things as classes? If
- >you're writing a descendant of the list class, you just make sure it
- >can handle the data directly, without the overhead of putting it in a
- >class.
-
-
- Object Oriented programming - data hiding, abstraction (see Booch)
- The list class shoudln't include any item specific code, otherwise
- abstraction principle is broken. I am not going to go into details why
- this is bad, see Booch's book.
-
-
- >
- >>Consequences:
- >>
- >>- A list class for each item class, hence we end up with twice as many
- >> classes. Furthermore we are placing some (little) item specific code
- >> into the list class; item specific code really belongs in the item
- >> class!
- >
- >No, you end up with the same number of classes. *You* need to write a
- >separate class for each item to be put into the list. *I* need to
- >write a separate class for each kind of list. I don't need to put
- >sorting information into items; sorting is what the list does.
-
-
- Sorting algorithm is still in the list class (binary search, quick sort,
- ..). However the item comparison shouldn't go into the list class, but
- item classes. Why? Because items "know" how to compare themselves to
- other items. Once again see Booch.
-
-
- >
- >>- A list may only contain a single type of item. The MI solution's list
- >> can store more than one type of item provided that the appropriate
- >> comparison functions are defined (so a list contain strings, integeres
- >> and money)
- >
- >Why do you think this? The list can contain *anything*. If I did
- >decide to put multiple kinds of items into the list, I would probably
- >put them in some kind of common container, but I don't need to. I can
- >just do a run-time check of the type of each item. This would require
- >them to be classes, but it wouldn't require them to know they're in
- >the list.
- >
-
-
- Yes, but whenever the item classes change you must go back and change the
- list class. This is exactly what should be avoided. So if you got the
- list class from a vendor in a library you should be able to create new
- item classes and store them in the list without making any changes to the
- list class. This is ideally what we'd want (at least I would). Once you
- implement the list you shouldn't have to go back and change it. So the
- sort method should sort an abstract item class without having to know
- details of item comparison. Again because items change the list must be
- insulated from item internals, including the comparison code.
-
-
- >>Finally to put the discussion into perspective. #1 is obviously the best
- >>and most elegant solution. Yet even without MI (Delphi) it is doable. So
- >>the price we pay in Delphi is that the solution is not quite as elegant.
- >
- >No, I don't think there is really that much difference. Everything
- >I've said above about the "right" way to implement a list would also
- >be the "right" way to do it in C++. I suspect MI has been used for
- >this just because C++ has MI, not because it makes sense to implement
- >a list that way.
- >
- >Duncan Murdoch
-
-
- Well "the right way" is:
- 1) non-OO way which is what we both suggested (I had it as #2 or #3)
- 2) OO way using MI (#1)
-
- They are both "right", but I still think that the OO way is more elegant.
- Also MI wasn't used just because C++ has it and Delphi doesn't, but
- because of the OO principles! I personaly am not convinced of MI
- necessity, but sometimes it does come in handy, like in this example.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-